<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    div {
      width: 100px;
      height: 100px;
      background-color: aquamarine;
      position: absolute;
      left: 0;
      top: 0;
    }
  </style>
  <body>
    <div></div>
    <script>
      var oDiv = document.getElementsByTagName('div')[0];
      oDiv.onclick = function () {
        newTon(this);
      };
      function newTon(dom) {
        clearInterval(dom.timer);
        var speedX = 6;
        var speedY = 8;
        var g = 3;
        dom.timer = setInterval(() => {
          speedY += g;
          speedY *= 0.8;
          var newTop = dom.offsetTop + speedY;
          var newLeft = dom.offsetLeft + speedX;
          if (
            newTop >
            document.documentElement.clientHeight - dom.clientHeight
          ) {
            speedY = -speedY;
          }
          if (newTop == 0) {
            speedY = -speedY;
          }
        }, 30);
      }
    </script>
  </body>
</html>
